using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class ImagesDAO
	{
		public ImagesDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Images> GetImagess()
		{
			try
			{
				List<Images> lstImagess = new List<Images>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTImagess",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Images oImages = new Images();
                    oImages.RowNum = Convert.ToInt32(oDbDataReader["RowNum"]);
					oImages.Id = Convert.ToInt32(oDbDataReader["Id"]);

					if(oDbDataReader["Title"] != DBNull.Value)
						oImages.Title = Convert.ToString(oDbDataReader["Title"]);

					if(oDbDataReader["ImgPath"] != DBNull.Value)
						oImages.ImgPath = Convert.ToString(oDbDataReader["ImgPath"]);

					if(oDbDataReader["ClickUrl"] != DBNull.Value)
						oImages.ClickUrl = Convert.ToString(oDbDataReader["ClickUrl"]);

					if(oDbDataReader["ImgType"] != DBNull.Value)
						oImages.ImgType = Convert.ToInt32(oDbDataReader["ImgType"]);

					if(oDbDataReader["IsActive"] != DBNull.Value)
						oImages.IsActive = Convert.ToBoolean(oDbDataReader["IsActive"]);

					if(oDbDataReader["Sorted"] != DBNull.Value)
						oImages.Sorted = Convert.ToInt32(oDbDataReader["Sorted"]);
					lstImagess.Add(oImages);
				}
				oDbDataReader.Close();
				return lstImagess;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
        public List<Images> GetBanner()
        {
            try
            {
                List<Images> lstImagess = new List<Images>();
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTBanners", CommandType.StoredProcedure);
                DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
                while (oDbDataReader.Read())
                {
                    Images oImages = new Images();
                    oImages.RowNum = Convert.ToInt32(oDbDataReader["RowNum"]);
                    oImages.Id = Convert.ToInt32(oDbDataReader["Id"]);

                    if (oDbDataReader["Title"] != DBNull.Value)
                        oImages.Title = Convert.ToString(oDbDataReader["Title"]);

                    if (oDbDataReader["ImgPath"] != DBNull.Value)
                        oImages.ImgPath = Convert.ToString(oDbDataReader["ImgPath"]);

                    if (oDbDataReader["ClickUrl"] != DBNull.Value)
                        oImages.ClickUrl = Convert.ToString(oDbDataReader["ClickUrl"]);

                    if (oDbDataReader["ImgType"] != DBNull.Value)
                        oImages.ImgType = Convert.ToInt32(oDbDataReader["ImgType"]);

                    if (oDbDataReader["IsActive"] != DBNull.Value)
                        oImages.IsActive = Convert.ToBoolean(oDbDataReader["IsActive"]);

                    if (oDbDataReader["Sorted"] != DBNull.Value)
                        oImages.Sorted = Convert.ToInt32(oDbDataReader["Sorted"]);
                    lstImagess.Add(oImages);
                }
                oDbDataReader.Close();
                return lstImagess;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<Images> GetPartners()
        {
            try
            {
                List<Images> lstImagess = new List<Images>();
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTPartners", CommandType.StoredProcedure);
                DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
                while (oDbDataReader.Read())
                {
                    Images oImages = new Images();
                    oImages.RowNum = Convert.ToInt32(oDbDataReader["RowNum"]);
                    oImages.Id = Convert.ToInt32(oDbDataReader["Id"]);

                    if (oDbDataReader["Title"] != DBNull.Value)
                        oImages.Title = Convert.ToString(oDbDataReader["Title"]);

                    if (oDbDataReader["ImgPath"] != DBNull.Value)
                        oImages.ImgPath = Convert.ToString(oDbDataReader["ImgPath"]);

                    if (oDbDataReader["ClickUrl"] != DBNull.Value)
                        oImages.ClickUrl = Convert.ToString(oDbDataReader["ClickUrl"]);

                    if (oDbDataReader["ImgType"] != DBNull.Value)
                        oImages.ImgType = Convert.ToInt32(oDbDataReader["ImgType"]);

                    if (oDbDataReader["IsActive"] != DBNull.Value)
                        oImages.IsActive = Convert.ToBoolean(oDbDataReader["IsActive"]);

                    if (oDbDataReader["Sorted"] != DBNull.Value)
                        oImages.Sorted = Convert.ToInt32(oDbDataReader["Sorted"]);
                    lstImagess.Add(oImages);
                }
                oDbDataReader.Close();
                return lstImagess;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
		public Images GetImages(int Id)
		{
			try
			{
				Images oImages = new Images();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTImages",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oImages.Id = Convert.ToInt32(oDbDataReader["Id"]);

					if(oDbDataReader["Title"] != DBNull.Value)
						oImages.Title = Convert.ToString(oDbDataReader["Title"]);

					if(oDbDataReader["ImgPath"] != DBNull.Value)
						oImages.ImgPath = Convert.ToString(oDbDataReader["ImgPath"]);

					if(oDbDataReader["ClickUrl"] != DBNull.Value)
						oImages.ClickUrl = Convert.ToString(oDbDataReader["ClickUrl"]);

					if(oDbDataReader["ImgType"] != DBNull.Value)
						oImages.ImgType = Convert.ToInt32(oDbDataReader["ImgType"]);

					if(oDbDataReader["IsActive"] != DBNull.Value)
						oImages.IsActive = Convert.ToBoolean(oDbDataReader["IsActive"]);

					if(oDbDataReader["Sorted"] != DBNull.Value)
						oImages.Sorted = Convert.ToInt32(oDbDataReader["Sorted"]);
				}
				oDbDataReader.Close();
				return oImages;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddImages(Images oImages)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTImages",CommandType.StoredProcedure);
				if (oImages.Title!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oImages.Title));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,DBNull.Value));
				if (oImages.ImgPath!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgPath",DbType.String,oImages.ImgPath));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgPath",DbType.String,DBNull.Value));
				if (oImages.ClickUrl!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ClickUrl",DbType.String,oImages.ClickUrl));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ClickUrl",DbType.String,DBNull.Value));
				if (oImages.ImgType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgType",DbType.Int32,oImages.ImgType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgType",DbType.Int32,DBNull.Value));
				if (oImages.IsActive.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsActive",DbType.Boolean,oImages.IsActive));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsActive",DbType.Boolean,DBNull.Value));
				if (oImages.Sorted.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Sorted",DbType.Int32,oImages.Sorted));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Sorted",DbType.Int32,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateImages(Images oImages)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATEImages",CommandType.StoredProcedure);
				if (oImages.Title!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oImages.Title));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,DBNull.Value));
				if (oImages.ImgPath!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgPath",DbType.String,oImages.ImgPath));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgPath",DbType.String,DBNull.Value));
				if (oImages.ClickUrl!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ClickUrl",DbType.String,oImages.ClickUrl));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ClickUrl",DbType.String,DBNull.Value));
				if (oImages.ImgType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgType",DbType.Int32,oImages.ImgType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ImgType",DbType.Int32,DBNull.Value));
				if (oImages.IsActive.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsActive",DbType.Boolean,oImages.IsActive));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsActive",DbType.Boolean,DBNull.Value));
				if (oImages.Sorted.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Sorted",DbType.Int32,oImages.Sorted));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Sorted",DbType.Int32,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oImages.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveImages(Images oImages)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEImages",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oImages.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveImages(int Id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEImages",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
